#ifndef __AVOID_HEAD_FILE_INCLUDED_CLIP_BARD__
#define __AVOID_HEAD_FILE_INCLUDED_CLIP_BARD__
#include <Windows.h>
#include <string>
#include "../x/textpack.h"

namespace swui
{
	inline void clipboard_copy(const std::wstring& str)
	{
		OpenClipboard(NULL);
		EmptyClipboard();
		unsigned memsize = (str.size() + 1) * sizeof(std::wstring::value_type);
		HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, memsize);

		std::wstring::value_type *txt = static_cast<std::wstring::pointer>(GlobalLock(hMem));
		memcpy(txt, str.c_str(), memsize - sizeof(std::wstring::value_type));
		txt[str.size()] = '\0';
		GlobalUnlock(hMem);

		SetClipboardData(CF_UNICODETEXT, hMem);
		CloseClipboard();
	}
	inline void clipboard_get(_ctlInterior::textpack& pack)
	{
		OpenClipboard(NULL);

		HANDLE hMem = GetClipboardData(CF_UNICODETEXT);
		if(hMem !=  NULL)
		{
			pack.set(static_cast<std::wstring::const_pointer>(GlobalLock(hMem)));
			GlobalUnlock(hMem);
		}
		CloseClipboard();
	}
}

#endif